package com.reactim.user.task;

import com.reactim.user.service.FriendRequestService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 好友请求清理定时任务
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class FriendRequestCleanupTask {
    
    private final FriendRequestService friendRequestService;
    
    /**
     * 清理过期的好友请求
     * 每天凌晨2点执行
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void cleanupExpiredRequests() {
        try {
            log.info("开始清理过期好友请求");
            
            int cleanedCount = friendRequestService.cleanupExpiredRequests();
            
            log.info("过期好友请求清理完成，清理数量: {}", cleanedCount);
            
        } catch (Exception e) {
            log.error("清理过期好友请求失败", e);
        }
    }
}